package priv.winnine.util;

import org.springframework.util.StringUtils;
import priv.winnine.annotation.TimeStamp;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

public class TimeStampValidator implements ConstraintValidator<TimeStamp, String> {

    private String reg = "^[0-9]{1,13}$";//表示时间戳的正则表达式
    private Pattern pattern = Pattern.compile(reg);

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if (value == null || StringUtils.isEmpty(value)) return true;
        if (value.length() != 13) return false;
        return pattern.matcher(value).matches();
    }

}
